﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using ControlAccessUser.Presenter;
using ControlAccessUser.Model;

namespace ControlAccessUser.Tests
{
    [TestClass]
    public class UserRegisterTest
    {
        MockUserRegisterView vUserRegisterView;
        PresenterUserRegister pUserRegister;

        [TestInitialize]
        public void Initial()
        {
            vUserRegisterView = new MockUserRegisterView();
            pUserRegister = new PresenterUserRegister(vUserRegisterView);
            ControlAccessUser.DataAccess.ControlAccessUserEntities.Instance.Users.Add(new User() {UserFirstName="Mario", UserLastName="Peredo",UserName="mario",UserPassword="mario123" });
            ControlAccessUser.DataAccess.ControlAccessUserEntities.Instance.SaveChanges();
        }

        [TestCleanup]
        public void Clean()
        {
            ControlAccessUser.DataAccess.ControlAccessUserEntities.Instance.LimpiarDB();
        }


        [TestMethod]
        public void RegisterUser()
        {
            vUserRegisterView.EnterHisData();
            pUserRegister.RegisterUser();
            Assert.AreEqual(Message.RegisterSuccessfully,vUserRegisterView.SystemMessage);
        }

        [TestMethod]
        public void RegisterUserWithExistingUser()
        {
            vUserRegisterView.EnterUserExit();
            pUserRegister.RegisterUser();
            Assert.AreEqual(Message.UserAlreadyExist, vUserRegisterView.ErrorMessage);
        }

        [TestMethod]
        public void RegisterUserWithFieldsEmpty()
        {
            pUserRegister.RegisterUser();
            Assert.AreEqual(Message.NullOrEmptyFields, vUserRegisterView.ErrorMessage);
        }
        
    }
}
